package com.u.iot.engineering.controller;


import com.u.iot.engineering.entity.ServerState;
import com.u.iot.engineering.service.IServerStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/server-state")
public class ServerStateController {

    @Autowired
    private IServerStateService serverStateService;

    @GetMapping
    public List<ServerState> getAllServerStates() {
        return serverStateService.list();
    }

    @GetMapping("/{id}")
    public ServerState getServerStateById(@PathVariable Long id) {
        return serverStateService.getById(id);
    }

    @PostMapping
    public void createServerState(@RequestBody ServerState serverState) {
        serverStateService.save(serverState);
    }

    @PutMapping("/{id}")
    public void updateServerState(@PathVariable Long id, @RequestBody ServerState serverState) {
        serverState.setId(id);
        serverStateService.updateById(serverState);
    }

    @DeleteMapping("/{id}")
    public void deleteServerState(@PathVariable Long id) {
        serverStateService.removeById(id);
    }

}
